// 转亿和万单位

export function changeValue(num) {
  let res = 0;
  if (num >= 1000000000) {
    res = num / 1000000000;
    res = res.toFixed(2) + "亿";
  } else if (num > 10000) {
    res = num / 10000;
    res = res.toFixed(2) + "万";
  }
  return res;
}

// 获取随机数
export function getRandomNum(num) {
  return Math.round(Math.random() * num);
}
//让数组里面元素随机排序
export function randomSort(array) {
  let length = array.length;

  if (!Array.isArray(array) || length <= 1) return;

  for (let index = 0; index < length - 1; index++) {
    let randomIndex = Math.floor(Math.random() * (length - index)) + index;
    [array[index], array[randomIndex]] = [array[randomIndex], array[index]];
  }

  return array;
}
